package com.bishe.tax.controller.sys;

import com.bishe.tax.entity.SysUser;
import com.bishe.tax.service.SysUserService;
import com.bishe.tax.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by xian on 2019/4/6.
 * <p>
 * This project is jianyu
 */
@Controller
@RequestMapping("sys/login")
public class LoginController {

	@Autowired
	private SysUserService userService;

	@GetMapping("/")
	public String toLogin() {
		return "home/login";
	}

	@PostMapping("/")
	@ResponseBody
	public AjaxResult login(SysUser user, @RequestParam("code") String code, HttpSession session) {
		return userService.doUserLogin(user, code, session);
	}

	@GetMapping("out")
	public String logout(HttpSession session) {
		session.removeAttribute("loginUser");
		return toLogin();
	}

}
